package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.entity.Bill;
import com.zzyl.mapper.BillMapper;
import com.zzyl.service.BillService;
import com.zzyl.vo.BillVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BillServiceImpl implements BillService {

    @Autowired
    private BillMapper billMapper;

    /**
     * 分页查询
     *
     * @param name
     * @param transactionStatus
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageResponse<BillVo> list(String name, Integer transactionStatus, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<BillVo> page = billMapper.list(name,transactionStatus);
        PageResponse<BillVo> pageResponse = new PageResponse<>();
        pageResponse.setPage(pageNum);
        pageResponse.setPageSize(pageSize);
        pageResponse.setTotal(page.getTotal());
        pageResponse.setRecords(page.getResult());
        return pageResponse;
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Override
    public BillVo findByID(Long id) {
        Bill bill = billMapper.finById(id);
        BillVo billVo = new BillVo();
        BeanUtils.copyProperties(bill,billVo);
        return billVo;
    }


}
